#ifndef _MY_BULLET_H_
#define _MY_BULLET_H_
#include "cocos2d.h"
#include "myobject.h"
#include "zonemanager.h"
#include "sceneobject/sceneobjectbase.h"
#include <list>

using namespace cocos2d;
using namespace std;

namespace fireplane
{
	class Enemy;
	class Player;

	class Bullet : public Object
	{
	public:
		enum BulletOwner{
			BO_PLAYER,
			BO_ENEMY,
		};

		enum BulletType{
			BT_dir_bullet = 0,
			BT_sin_path_bullet,
			BT_ji_guang,
			BT_laser_bullet,
		};

		enum BulletImg{
			BI_img0 = 0,
			BI_img1,
			BI_img2,
			BI_img3,

			BI_img5,
			BI_img6,
			BI_img7,

			BI_img15,
			BI_img16,
	        BI_img17,
			BI_img18

		};

		struct BulletCommand
		{
			BulletCommand(BulletType t):_type(t){}
			CCPoint _pos;
			CCPoint _dir;
			float _speed;
			BulletImg _img;
			BulletOwner o;

			BulletType _type;
		};

		// all bullets
		static Bullet* _createBullet(BulletCommand* cmd);
		static void updateAllBullets(float dt);
		static void initBulletManager(CCNode* parent);
		static void destroyBulletManager();
		static void pushCommand(BulletCommand* cmd);
		static void processCmd();
		//////////////////////////////////////////////////////////////////////////

		Bullet();
		~Bullet();

		virtual bool isCollision2Player(Player* player);
		virtual bool isCollision2Eneny(Enemy* enemy);
		virtual bool isCollision2SceneObject(SceneObjectBase* sceneobject);

		virtual void init(BulletCommand* cmd);

		BulletOwner getBulletOwner(){
			return _owner;
		}

		bool updateState(float dt);
		virtual void destroy();

		void onAttack();

		static list<Bullet*>& getAllBullets(){
			return _all_active_bullets;
		}

		virtual CCPoint getWorldPos();
	
	protected:
		CCPoint _dir;
		CCSprite* _body;
		float _speed;
		int _lastZoneIdx;
		int _currentZoneIdx;

		BulletOwner _owner;

		// all bullets
		static CCNode* _all_bullets_parent;
		static list<Bullet*> _all_active_bullets;
		static list<BulletCommand*> _all_commands;
		//////////////////////////////////////////////////////////////////////////
	};
}

#endif